package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.Burse;
import po.Winner;
import service.BurseService;

@Controller
public class burseController {
	
	// 依赖注入
	@Autowired
	private BurseService burseService;	
	@RequestMapping(value = "/burse/getBurse.action")
	public String list( Model model) {
		List<Burse> burselist = burseService.getBurseList();
		model.addAttribute("burselist", burselist);	
		return "burse_list";

	}
	@RequestMapping("/burse/delBurse.action")
	public String burseDelete(Integer burseid) {
		int rows = burseService.deleteBurse(burseid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/burse/getBurse.action";
	}
	@RequestMapping("/burse/addBurse.action")
	public String burseAdd(Burse burse) {
		int rows = burseService.addBurse(burse);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/burse/delBurse.action";
	}
	
	@RequestMapping(value ="/burse/getburseId.action")
	@ResponseBody
	public Burse getBurseId(Integer id) {
		Burse data = burseService.getBurseId(id);
		return data;
   }  
	
	@RequestMapping(value ="/burse/updateBurse.action")
	@ResponseBody
	public String updateBurse(Burse burse) {
		int row = burseService.updateBurse(burse);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   }
	@RequestMapping(value = "/burse/findAll.action")
	public String listAll(String data,Model model) {	
		List<Burse> burselist = burseService.findList(data);
		model.addAttribute("burselist", burselist);	
		return "burse_list";
	}
}
